package com.lzh.farmersshop;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.core.env.Environment;

import java.awt.*;
import java.net.URI;
import java.net.URISyntaxException;

@MapperScan("com.lzh.farmersshop.mapper")
@ServletComponentScan
@SpringBootApplication
public class FarmersShopApplication {

    private static Environment environment;

    @Autowired
    public void setEnvironment(Environment environment) {
        FarmersShopApplication.environment = environment;
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(FarmersShopApplication.class, args);
        // 获取项目启动的端口
        String port = environment.getProperty("local.server.port");

        // 指定要请求的url
        String url = "http://localhost:" + port + "/mall/index";
        // Java获取默认系统桌面
        if (Desktop.isDesktopSupported()) {
            Desktop desktop = Desktop.getDesktop();

            // 判断系统桌面是否支持要执行的功能
            if (desktop.isSupported(Desktop.Action.BROWSE)) {

                URI uri = new URI(url);
                desktop.browse(uri);
            }
        } else {
            Runtime runtime = Runtime.getRuntime();
            runtime.exec("rundll32 url.dll,FileProtocolHandler " + url);
        }
    }

}
